package com.example.aigc_education.ws.handler;

import com.example.aigc_education.integration.request.ChatMessageRequestV2;
import com.example.aigc_education.rpc.api.v2.ChatServiceProto;
import com.example.aigc_education.ws.response.LinkMessage;

public class LinkMessageHandler extends AbstractMessageHandler {

    @Override
    protected int getRole() {
        return ChatServiceProto.Role.AI_VALUE;
    }

    @Override
    protected String getType() {
        return "link";
    }

    @Override
    public ChatMessageRequestV2 handle(ChatServiceProto.ChatMessage chatMessage) {
        LinkMessage message = new LinkMessage();
        message.setTitle(chatMessage.getContents(0).getLink().getTitle());
        message.setContent(chatMessage.getContents(0).getLink().getContent());
        message.setSitename(chatMessage.getContents(0).getLink().getSitename());
        message.setSummary(chatMessage.getContents(0).getLink().getSummary());
        message.setLinkId(chatMessage.getContents(0).getLink().getLinkId());
        message.setUrl(chatMessage.getContents(0).getLink().getUrl());
        return ChatMessageRequestV2.builder()
                .userId(String.valueOf(chatMessage.getUserId()))
                .type(chatMessage.getContents(0).getType())
                .role(ChatMessageRequestV2.Role.AI)
                .content(message)
                .messageId(chatMessage.getMessageId())
                .convId(String.valueOf(chatMessage.getConvId()))
                .build();
    }
}
